/*
 * @Author: your name
 * @Date: 2020-08-30 15:00:51
 * @LastEditTime: 2020-11-16 09:29:03
 * @LastEditors: your name
 * @Description: 字典
 * @FilePath: \adminPC\src\store\modules\dictionary.js
 */
import { getDictListByType } from '@/api/dictionaries'

const state = {
  dic: {}
}

const mutations = {
  SET_DicByType(state, { type, value }) {
    const oldData = state.dic
    state.dic = { ...oldData, [type]: value }
  }
}

const actions = {
  getDictListByType({ commit }, type) {
    getDictListByType({ dictTypeCode: type }).then(res => {
      const { code, data: value = [] /* message */ } = res
      if (code === 200) {
        commit('SET_DicByType', { type, value })
      }
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

